function Get-NewFirewallRuleName {
    param ([Parameter(Mandatory = $false)][Microsoft.Azure.Commands.Sql.FirewallRule.Model.AzureSqlServerFirewallRuleModel[]]$Rules)

    # Firewall rule name.
    $FirewallRuleName = 'ADF'
    $FirewallRuleRegex = "^$FirewallRuleName\d*$"

    # Only look at firewall rules that match $FirewallRuleName.
    $FilteredArr = ($Rules | Where-Object { $_.FirewallRuleName -match $FirewallRuleRegex }).FirewallRuleName

    # Generate new name.
    if ($FilteredArr) {
        # Increment the name. E.g. ADF7 -> ADF8
        [array]$sorted = $FilteredArr | Sort-Object
        return ($FirewallRuleName + ([int]$sorted[-1].Substring($FirewallRuleName.Length) +1))
    } else {
        # Starts a new sequence. E.g. ADF0
        return ($FirewallRuleName + 0)
    }
}